<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <title>admin</title>

    <meta name="keywords" content="">
    <meta name="description" content="">
    <link rel="shortcut icon" href="/favicon.ico"/>
    <css href="/static/css/admin/bootstrap.min14ed.css"/>
    <css href="/static/css/admin/font-awesome.min93e3.css"/>
    <css href="/static/css/admin/animate.min.css"/>
    <css href="/static/css/admin/plugins/summernote/new_sumnote.css"/>
    <css href="/static/css/admin/plugins/summernote/summernote-bs3.css"/>
    <css href="/static/css/admin/plugins/chosen/chosen.css"/>
    <css href="/static/css/admin/plugins/datapicker/datepicker3.css"/>
    <css href="/static/css/admin/plugins/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css"/>
    <css href="/static/css/admin/style.min862f.css"/>
    <link href="/static/css/admin/admincommon.css?v=20181116" rel='stylesheet' type='text/css'/>
    <link href="/static/css/layui/css/layui.css" rel='stylesheet' type='text/css'/>
</head>
<style type="text/css">
    .chosen-container-multi {
        margin-left: 16px;
    }
</style>
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <form id="article_form" method="post" class="form-horizontal">
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-1 control-label">文章标题</label>
                    <div class="col-sm-6">
                        <input type="text" name="title" value="{$data['title']}" class="form-control">
                        <input type="hidden" name="id" value="{$data['id']}" class="form-control">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-1 control-label">文章作者</label>
                    <div class="col-sm-6">
                        <input type="text" name="author" value="{$data['author']}" class="form-control">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-1 control-label">选择语言</label>
                    <div class="col-sm-6">
                        <input type="radio" id="radio-1" value="0"
                               name="language" <?php if($data['language'] == 0){ echo 'checked';} ?> />
                        <label for="radio-1">中文</label>
                        &nbsp&nbsp&nbsp&nbsp&nbsp
                        <input type="radio" id="radio-2" value="1"
                               name="language" <?php if($data['language'] == 1){ echo 'checked';} ?> />
                        <label for="radio-2">英文</label>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-1 control-label">文章图片</label>
                    <div class="col-sm-2">
                        <input type="file" id="article_poster" name="file" value="" class="form-control input-file"
                               onchange="getImgData(this);" style="height: 40px;">
                        <input type="hidden" id="photo" name="cover_image" value="{$data['cover_image']}"
                               class="form-control input-file">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-1 control-label">预览图片</label>
                    <div class="" id="temp_picture_wrap" style="position:relative;">
                        <if condition="$data['cover_image']">
                            <img src="{$domain}{$data['cover_image']}" id="temp_picture" width="240" height="250"
                                 style="margin-top:15px;"/>
                            <a class='del_temp_picture' style='position:absolute;bottom:0px;margin-left:10px;'>删除</a>
                        </if>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-1 control-label">文章简介</label>
                    <div class="col-sm-6">
                        <script src="/static/ueditor/ueditor.config.js" type="text/javascript"></script>
                        <script src="/static/ueditor/ueditor.all.js" type="text/javascript"></script>
                        <textarea name="introduction" id="introduction" cols="30" rows="10">{$data['introduction']}</textarea>
                        <script type="text/javascript">
                            var editor = new UE.ui.Editor();
                            editor.render("introduction");
                        </script>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-1 control-label">文章内容</label>
                    <div class="col-sm-6">
                        <textarea name="content" id="articleEditor">{$data['content']}</textarea>
                        <script type="text/javascript">
                            var editor = new UE.ui.Editor();
                            editor.render("articleEditor");
                        </script>
                    </div>
                </div>
            </div>

            <div style="margin-left: 140px" class="row">
                <button class="btn btn-primary" type="submit">保存内容</button>
            </div>
        </div>
    </form>
</div>
<js href="/static/js/admin/jquery.min.js"/>
<js href="/static/js/admin/bootstrap.min.js"/>
<js href="/static/js/admin/content.min.js"/>
<js href="/static/js/admin/plugins/chosen/chosen.jquery.js"/>
<js href="/static/js/admin/plugins/summernote/new_sumnote.js"/>
<js href="/static/js/admin/plugins/summernote/summernote-zh-CN.js"/>
<js href="/static/js/admin/plugins/layui/layer/layer.js"/>
<js href="/static/js/admin/plugins/datapicker/bootstrap-datepicker.js"/>
<js href="/static/css/layui/layui.js"/>
<script>
    layui.use('colorpicker', function () {
        var $ = layui.$
            , colorpicker = layui.colorpicker;
        //表单赋值
        colorpicker.render({
            elem: '#test-form'
            , color: '#1c97f5'
            , done: function (color) {
                $('#test-form-input').val(color);
            }
        });
    });
    $(document).ready(function () {

        $("#temp_picture_wrap").on("click", '.del_temp_picture', function () {
            $("#article_poster").val('');
            $("#hide_article_poster").val('');
            $("#temp_picture_wrap").empty();
        });

        $('.summernote').summernote({
            lang: "zh-CN",
            height: '300px',
            callbacks: {
                onImageUpload: function (files) {
                    var formData = new FormData();
                    formData.append('file', files[0]);
                    $.ajax({
                        url: "{:url('admin/Upload/checkUploadFileInfo')}?isupload=2&folder=article",//后台文件上传接口
                        type: 'post',
                        data: formData,
                        processData: false,
                        contentType: false,
                        success: function (data) {
                            if (data.code == 1) {

                                $('.summernote').summernote('insertImage', data.data, 'cover_image');

                            } else {

                                layer.msg(data.msg, {time: 800, icon: 2});
                            }
                        },
                        dataType: 'json'
                    });
                }
            }
        });

        $("#article_add_time").datepicker();

        var chosen = $(".chosen-select").chosen({
            max_selected_options: 10,
            width: "50%"
        });
        chosen.bind("chosen:maxselected", function () {
            layer.msg('最多选10项', {time: 800, icon: 2});
        });
    });

    function getImgData(obj) {

        var file = obj.files[0];
        var formData = new FormData();

        var createObjectURL = function (blob) {

            return window[window.webkitURL ? 'webkitURL' : 'URL']['createObjectURL'](blob);
        };

        formData.append('file', file);

        $.ajax({
            url: "{:url('admin/Upload/checkUploadFileInfo')}?isupload=2&folder=product",
            type: 'post',
            processData: false,  // 异步传输 formData 时要加上  processData: false  contentType: false
            contentType: false,  // 否则会报 Illegal invocation 非法调用错误
            data: formData,
            success: function (data) {

                if (data.code == 1) {
                    var filedata = createObjectURL(file);
                    var imgObject = new Image();
                    imgObject.src = filedata;
                    imgObject.id = 'temp_picture';
                    imgObject.width = '240';
                    imgObject.height = '250';
                    imgObject.style.marginTop = '15px';

                    $('#temp_picture_wrap').html('').append(imgObject);
                    $('#temp_picture_wrap').append("<a class='del_temp_picture' style='position:absolute;bottom:0px;margin-left:10px;'>删除</a>");
                    $('#photo').val(data.data);
                } else {

                    $("#article_poster").val('');
                    $("#temp_picture_wrap").empty();
                    layer.msg(data.msg, {time: 800, icon: 2});
                }

            },
            dataType: 'json'
        });

    }

</script>
</html>
